package com.jn.retrofit.views;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jn.retrofit.R;
import com.jn.retrofit.base.BaseActivity;
import com.jn.retrofit.contract.QAndAContract;
import com.jn.retrofit.entity.QAndAEntity;
import com.jn.retrofit.presenter.QAndAPresenter;

public class QAndAActivity extends BaseActivity
        implements QAndAContract.IQAndAView, View.OnClickListener {
    private QAndAContract.IQAndAPresenter mPresenter;
    private Button mButton;
    private TextView mQuestionText;
    private TextView mAnswerText;

    @Override
    public int getLayoutId() {
        return R.layout.activity_qanda;
    }

    @Override
    public void init() {
        mPresenter = new QAndAPresenter(this, this);
        mButton = findViewById(R.id.button);
        mQuestionText = findViewById(R.id.question);
        mAnswerText = findViewById(R.id.answer);
        mButton.setOnClickListener(this);
    }

    @Override
    public void showData(QAndAEntity data) {
        if (data != null) {
            mQuestionText.setText(data.getQuestion());
            mAnswerText.setText(data.getAnswer());
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.button) {
            if (mPresenter != null) {
                mPresenter.getData();
            }
        }
    }
}
